package tag38_02_09.threadsWeiter;

public class Th16_synchStaticMethoden {
	
	static class GlobalIncrement{
		private static int count;
		
//		public static void increment(){
//			synchronized (GlobalIncrement.class){
//			count++;
//			}
//		}
		
		
		//Statische synchronized Methode synchoroniziert den ganze Body mit 
		// dem Klassen-Objekt (Klassenname.class)
		synchronized public static void increment(){
			count++;
		}
		
//		public static int getCount(){
//			synchronized (GlobalIncrement.class){
//			return count;
//			}
//		}
		
		synchronized public static int getCount(){
			return count;
		}
	}

	public static void main(String[] args) throws InterruptedException{
		Thread t1 = new Thread(){
			public void run(){
				GlobalIncrement.increment();
			}
		};
		
		
		t1.start();
		
		GlobalIncrement.increment();
		
		t1.join();
		
		System.out.println("static count: " + GlobalIncrement.getCount());
		
	}

}
